package com.yiquan.chat.dao;

import com.yiquan.chat.pojo.Converse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Tyrone
 * @date 2022/1/2 14:09
 */
public interface ConverseDao extends JpaRepository<Converse, Long>, JpaSpecificationExecutor<Converse> {

    @Query(nativeQuery = true, value = "select  * from yiquan_converse where from_user_id = ? and converse_state = 0")
    List<Converse> findByUserId(Long userId);

    @Query(nativeQuery = true, value = "select  * from yiquan_converse where from_user_id = ?1 and to_user_id = ?2 and converse_state = 0")
    Converse getByFromUserIdAndToUserId(Long userId, Long theUserId);

    @Query(nativeQuery = true, value = "select * from yiquan_converse where converse_id = ?")
    Converse findByConverseId(Long converseId);
}
